<?php
namespace App\Http\Controllers\Admin;
use App\DTOS\Admin\ActiveCodeSearchDTO;
use App\DTOS\Admin\ActiveRuleSearchDTO;
use App\Models\Game\ActiveCode;
use App\Models\ActiveRule;
use App\Models\ActiveRuleOline;
use App\Models\ActiveRuleOlineqd;
use App\Models\ActiveRuleQd;
use App\Services\Game\ActiveCodeService;
use App\Services\Game\ActiveRuleService;
use App\Utils\MyLog;
use Maatwebsite\Excel\Facades\Excel;
use App\Exports\ExcelExport;
use App\Http\Controllers\Controller;
use App\Utils\ResponseUtil;
use App\DTOS\Admin\FeedBackSearchDTO;
use App\Services\FeedBackService;
use App\DTOS\Admin\FeedBackInsertDTO;
use App\DTOS\Admin\FeedBackUpdateDTO;
class ActiveCodeController extends Controller
{
    private ActiveCodeService $service;

    /**
     * FeedBackService constructor.
     * @param ActiveCodeService $service
     */
    public function __construct(ActiveCodeService $service)
    {
        $this->service = $service;
    }

    public function paginate()
    {
        $DTO = new ActiveCodeSearchDTO(request()->all());
        $paginate = $this->service->paginate($DTO);
        $data = $paginate->items();

        $res = [];
        $res['code'] = 0;
        $res['data'] = $data;
        $res['count'] = $paginate->total();
        return ResponseUtil::json($res);
    }

    public function paginatelog()
    {
        $DTO = new ActiveCodeSearchDTO(request()->all());
        $paginate = $this->service->paginatelog($DTO);
        $data = $paginate->items();

        $res = [];
        $res['code'] = 0;
        $res['data'] = $data;
        $res['count'] = $paginate->total();
        return ResponseUtil::json($res);
    }


    public function edit($id)
    {
        try{

            $DTO = new ActiveCodeSearchDTO(request()->post());
            $this->service->updateById($id,$DTO);
            return ResponseUtil::success();
        } catch (\Exception $e){
            return ResponseUtil::error($e->getMessage());
        }
    }

    public function delete($id){
        try{
            $this->service->deleteById($id);
            return ResponseUtil::success();
        } catch (\Exception $e){
            return ResponseUtil::error($e->getMessage());
        }
    }
    public function detail($id)
    {
        $data = $this->service->getById($id);
        return ResponseUtil::success($data);
    }

    public function add() {
        // 获取请求的数据
        $data = request()->only([
            'num',
            'name',
            'TypeId',
            'ServerType',
            'ServerList',
            'TimeType',
            'TimeOpen',
            'TimeEnd',
            'LoopType',
            'LoopVal',
            'LoopDayTimeLimitStart',
            'LoopDayTimeLimitEnd',
            'DayRefreshTime',
            'UIInFuncId',
            'UIInFuncIdParam',
            'IsSysMsg',
            'Rebirth',
            'ExclusionAction',
            'serverGroup',
             'rmark'
        ]);

        // 添加创建时间
        $data['created_at'] = date("Y-m-d H:i:s");

        // 插入数据
        ActiveCode::query()->insert($data);

        // 返回成功响应
        return ResponseUtil::success();
    }


}
